package com.lkd.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Strings;
import com.lkd.dao.VmPolicyDao;
import com.lkd.entity.PolicyEntity;
import com.lkd.entity.VmPolicyEntity;
import com.lkd.exception.LogicException;
import com.lkd.http.vo.PolicyReq;
import com.lkd.service.VmPolicyService;
import com.lkd.vo.Pager;
import lombok.val;
import org.bouncycastle.util.Longs;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Objects;

@Service
public class VmPolicyServiceImpl extends ServiceImpl<VmPolicyDao,VmPolicyEntity> implements VmPolicyService{



    /* 分页查询
     * 业务分析：
     *  1.判断关键数据据
     *    页数和页条数有默认值所以无需判断，policyName值非空时需要按名称查询
     *
     *  2.判断业务数据
     *    本次操作没有关联后端（数据库）其他数据，无需操作
     *  3.保持区域数据并返回结果
     * */





    public boolean add(PolicyReq policyReq) {
       //1、判断关键数据
//       if(Strings.isNullOrEmpty(policyReq.getPolicyName())||
//               ObjectUtils.isEmpty(policyReq.getDiscount())) {
//           throw new LogicException("传入参数与接口不匹配");
//       }
       VmPolicyEntity vmPolicyEntity = new VmPolicyEntity();
        BeanUtils.copyProperties(policyReq,vmPolicyEntity);

        boolean result = this.save(vmPolicyEntity);

        return result;
    }

    @Override
    public VmPolicyEntity searchByInnerCode(String innerCode) {

        LambdaQueryWrapper<VmPolicyEntity> qw = new LambdaQueryWrapper<>();
        qw.eq(VmPolicyEntity::getInnerCode,innerCode);
         val entity = this.getOne(qw);

        return entity;
    }
}
